package com.hzc.springchan.enums;

import com.hzc.springchan.constant.System;

/**
 * 对外错误码枚举
 * @author chen990627
 * @date 2022/09/06
 */

public enum PubError {

    /**
     * 全局：系统异常
     */
    RUNTIME_EXCEPTION(BusinessModel.GLOBAL, "01", "系统异常"),
    /**
     * 全局：用户未登录
     */
    USER_NOT_LOGIN(BusinessModel.GLOBAL, "02", "请先登录"),
    /**
     * 全局：短信发送失败
     */
    SMSCODE_SEND_ERROR(BusinessModel.GLOBAL, "03", "短信发送失败"),
    /**
     * 全局：邮件发送失败
     */
    EMSCODE_SEND_ERROR(BusinessModel.GLOBAL, "04", "邮件发送失败"),
    /**
     * 全局：token失效
     */
    TOKEN_EXPIRE(BusinessModel.GLOBAL, "05", "用户登录凭证已失效"),
    /**
     * 全局：token无效
     */
    INVALID_TOKEN(BusinessModel.GLOBAL, "06", "用户登录凭证无效"),
    /**
     * 全局：验证码校验失败
     */
    VERIFY_CODE_FAILED(BusinessModel.GLOBAL, "07", "验证码校验失败"),
    /**
     * 公共访问资源: 用户名或密码错误
     */
    LOGIN_FAILED(BusinessModel.ANONYMOUS, "01", "用户名或密码错误"),
    /**
     * 公共访问资源：该用户已存在
     */
    REGISTER_USERNAME_ERROR(BusinessModel.ANONYMOUS, "02", "该用户已存在"),
    /**
     * 公共访问资源：该用户不存在
     */
    USER_NOT_EXIST(BusinessModel.ANONYMOUS, "03", "该用户不存在"),
    /**
     * 公共访问资源：用户已注销
     */
    USER_DEREGISTER(BusinessModel.ANONYMOUS, "04", "用户已注销"),

    /**
     * 消息中心：不存在任何消息
     */
    NO_ANY_MESSAGE(BusinessModel.MESSAGE, "01", "当前登录用户未收到任何消息"),
    /**
     * 操作记录：参数错误
     */
    OPERATION_LOG_PARAM_ERROR(BusinessModel.OPERATION, "01", "操作记录参数错误");



    private BusinessModel model;

    private String code;

    private String errorDesc;

    PubError(BusinessModel model, String code, String errorDesc) {
        this.model = model;
        this.code = code;
        this.errorDesc = errorDesc;
    }

    private String errorCode;

    public String getErrorDesc() {

        return this.errorDesc;
    }

    public String getErrorCode() {

        StringBuilder errorCode = new StringBuilder(System.Error.PREFIX);
        errorCode.append(model.getCode()).append(System.Error.OUTSIDE).append(code);
        return errorCode.toString();
    }
}
